package com.sky.edumanageapi.teacher.dao.repository.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sky.edumanageapi.teacher.dao.repository.TeacherRepository;
import com.sky.edumanageapi.teacher.mapper.TeacherMapper;
import com.sky.edumanageapi.teacher.pojo.entity.Teacher;
import com.sky.edumanageapi.teacher.pojo.vo.TeacherVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


@Repository

public class TeacherRepositoryImpl implements TeacherRepository {

    @Autowired
    private TeacherMapper teacherMapper;


    @Override
    public List<TeacherVO> getTeacherList() {
        List<Teacher> teacherList = teacherMapper.selectList(null);

        List<TeacherVO> teacherVOList = new ArrayList<>();
        for (Teacher teacher : teacherList) {
            TeacherVO teacherVO = new TeacherVO();
            BeanUtils.copyProperties(teacher, teacherVO);
            teacherVOList.add(teacherVO);
        }

        return teacherVOList;
    }

    @Override
    public TeacherVO getTeacherDetail(Integer id) {
        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.eq("teacher_id", id);

        TeacherVO teacherVO = new TeacherVO();
        BeanUtils.copyProperties(teacherMapper.selectOne(teacherQueryWrapper), teacherVO);

        return teacherVO;

    }
}
